package net.sebpx.subgeste.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import net.sebpx.subgeste.form.Hospital;

@Repository
public class HospitalDAOImpl implements HospitalDAO{

	@Autowired
    private SessionFactory sessionFactory;
	
	public void addHospital(Hospital hospital) {
		sessionFactory.getCurrentSession().save(hospital);
	}


	public void removeHospital(int id) {
		Hospital hospital = (Hospital) sessionFactory.getCurrentSession().get(Hospital.class, id);
		if (hospital != null) {
			sessionFactory.getCurrentSession().delete(hospital);
		}
	}

	public List<Hospital> listHospitals() {
        return sessionFactory.getCurrentSession().createQuery("from Hospital")
                .list();
	}
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

}
